<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Wish extends CI_Controller {

	private $_data = array();

	public function __construct() {
		parent::__construct();

		$this->load->library('form_validation');
		$this->form_validation->set_message('required', '请填写%s');

		$this->load->model('wish_mdl');
	}
	
	public function index()
	{
		$wish_list = $this->wish_mdl->get_wish_list();

		$this->form_validation->set_rules('content', '祝福', 'required|trim');

		$this->_data['wish_list'] = $wish_list;
		$this->_data['page_title'] = '祝福';

		if ($this->form_validation->run() === FALSE) {
			
			$this->load->view('wish', $this->_data);
		} else {
			$name = $this->input->post('name', TRUE);
			$mobile = $this->input->post('mobile', TRUE);
			$content = $this->input->post('content', TRUE);

			$data = array(
				'name' => $name,
				'mobile' => $mobile,
				'content' => $content,
				'add_time' => date('Y-m-d H:i:s')
			);

			$this->wish_mdl->add_wish($data);

			redirect('wish');
		}
		
		
		
	}
}

/* End of file wish.php */
/* Location: ./application/controllers/wish.php */